﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Linq;

namespace MisprintTestingTool
{
    class DBFacultySpecialty
    {
        private static XDocument _xml = null;
        private static XDocument XmlDoc
        {
            get
            {
                if (_xml == null)
                {
                    _xml = XDocument.Load("Faculty.xml");
                }
                return _xml;
            }
        }

        public static List<string> GetSpecialtyList(string facultyCode)
        {
            var result = new List<string>();

            foreach (var faculty in XmlDoc.Element("FacultyDb").Elements("Faculty"))
            {
                if (faculty.Attribute("code").Value == facultyCode)
                {
                    foreach (var spec in faculty.Elements("Specilaity"))
                    {
                        result.Add(spec.Value);
                    }
                }
            }

            return result;
        }

        public static List<string> GetFacultyList()
        {            
            var result = new List<string>();

            foreach (var faculty in XmlDoc.Element("FacultyDb").Elements("Faculty"))
            {
                result.Add(faculty.Attribute("code").Value);
            }

            return result;
        }
    }
}
